Skip to content

Fix a rare crash in TSKSPKIHashCache#348

Open
fabianmuecke wants to merge 2 commits intodatatheorem:masterfrom
fabianmuecke:master
Open

Fix a rare crash in TSKSPKIHashCache#348
fabianmuecke wants to merge 2 commits intodatatheorem:masterfrom
fabianmuecke:master

Conversation

@fabianmuecke
Copy link

@fabianmuecke fabianmuecke commented Jul 14, 2025

This PR fixes #347 by adding a missing dispatch_sync when reading the cache on the main dispatch queue to write it to the file system. This should be safe, as the only dispatch_barrier_sync call does not access the main queue, so cannot cause a deadlock.

I tried to find a test that would replicate the issue and found one, that will randomly (maybe once out of 1000 runs) achieve that. All attempts to improve the reliability of the test were futile. I added it the the PR anyway. Feel free to remove, if you think it's useless.

@mat1th
Copy link

mat1th commented Oct 17, 2025

I do see the same issue in my project. What holds this pr back from merging?

@NSExceptional
Copy link

NSExceptional commented Feb 17, 2026

Does anyone have a crash log they can share? :)

Edit: oops, from #347:

Crashed: com.apple.main-thread
0  libobjc.A.dylib                0xafb0 realizeClassWithoutSwift(objc_class*, objc_class*) + 544
1  libobjc.A.dylib                0xacec realizeClassMaybeSwiftMaybeRelock(objc_class*, locker_mixin<lockdebug::lock_mixin<objc_lock_base_t> >&, bool) + 404
2  libobjc.A.dylib                0x9bcc lookUpImpOrForward + 880
3  libobjc.A.dylib                0x4cc4 _objc_msgSend_uncached + 68
4  Foundation                     0x208e8 -[NSDictionary(NSDictionary) encodeWithCoder:] + 484
5  Foundation                     0x21fb8 _encodeObject + 1180
6  Foundation                     0x3bf54 +[NSKeyedArchiver archivedDataWithRootObject:requiringSecureCoding:error:] + 92
7  Sendwave Production            0xcb76d8 __60-[TSKSPKIHashCache hashSubjectPublicKeyInfoFromCertificate:]_block_invoke.17 + 253 (TSKSPKIHashCache.m:253)
...
11 libdispatch.dylib              0x125b0 _dispatch_main_queue_callback_4CF + 44
...
16 UIKitCore                      0x22c62c -[UIApplication _run] + 888
17 UIKitCore                      0x22bc68 UIApplicationMain + 340
18 Sendwave Production            0x8260 main + 14 (main.swift:14)
19 ???                            0x1d59dedcc (Missing)

@ashokds
Copy link

ashokds commented Feb 18, 2026

@NSExceptional -- here is another

TSKSPKIHashCache.m:269 __60-[TSKSPKIHashCache hashSubjectPublicKeyInfoFromCertificate:]_block_invoke.17 + 269

          Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x144c objc_retain_x0 + 16
1  libobjc.A.dylib                0x144c objc_retain + 16
2  Foundation                     0x8ffcf4 -[NSDictionary(NSDictionary) encodeWithCoder:] + 472
3  Foundation                     0x1fd30 _encodeObject + 1176
4  Foundation                     0x94ce04 +[NSKeyedArchiver archivedDataWithRootObject:requiringSecureCoding:error:] + 88
5  DesignIt                     0xf0f704 __60-[TSKSPKIHashCache hashSubjectPublicKeyInfoFromCertificate:]_block_invoke.17 + 269 (TSKSPKIHashCache.m:269)
6  libdispatch.dylib              0x1adc _dispatch_call_block_and_release + 32
7  libdispatch.dylib              0x1b7fc _dispatch_client_callout + 16
8  libdispatch.dylib              0x38b10 _dispatch_main_queue_drain.cold.5 + 812
9  libdispatch.dylib              0x10ec8 _dispatch_main_queue_drain + 180
10 libdispatch.dylib              0x10e04 _dispatch_main_queue_callback_4CF + 44
11 CoreFoundation                 0x6a2b4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
12 CoreFoundation                 0x1db3c __CFRunLoopRun + 1944
13 CoreFoundation                 0x1ca6c _CFRunLoopRunSpecificWithOptions + 532
14 GraphicsServices               0x1498 GSEventRunModal + 120
15 UIKitCore                      0x9ddf8 -[UIApplication _run] + 792
16 UIKitCore                      0x46e54 UIApplicationMain + 336
17 DesignIt                     0x650d54 main + 14 (AppDelegate.swift:14)
18 ???                            0x1853c6e28 (Missing)
        

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash: EXC_BAD_ACCESS KERN_INVALID_ADDRESS in [TSKSPKIHashCache hashSubjectPublicKeyInfoFromCertificate:] line 253

5 participants